package com.dragon.sdgp.controller;

import com.dragon.sdgp.common.R;
import com.dragon.sdgp.entity.Lexicon;
import com.dragon.sdgp.entity.dto.LexiconDto;
import com.dragon.sdgp.service.LexiconService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @AUTHOR : Dragon_Yang
 * @File : LexiconController
 * @DESCRIPTION :
 * @DATE : 2023/3/17 19:38
 */
@RestController
@RequestMapping("/api/lexicon")
public class LexiconController {

    @Autowired
    private LexiconService lexiconService;

    @GetMapping("/list")
    public R getLexiconList(HttpServletRequest httpServletRequest,
                            @Param("key") String key,
                            @Param("page") Integer page){
        String token = httpServletRequest.getHeader("authorization");
        return lexiconService.getLexiconList(token, key, page);
    }

    @PostMapping("/add")
    public R addLexicon(HttpServletRequest httpServletRequest,
                        @RequestBody LexiconDto lexiconDto){
        String token = httpServletRequest.getHeader("authorization");
        return lexiconService.addLexicon(lexiconDto, token);
    }

    @GetMapping("/listByAccount")
    public R getLexiconListByAccount(HttpServletRequest httpServletRequest){
        String token = httpServletRequest.getHeader("authorization");
        return lexiconService.getLexiconListByAccount(token);
    }

    @GetMapping("/collection")
    public R getLexiconListCollection(HttpServletRequest httpServletRequest){
        String token = httpServletRequest.getHeader("authorization");
        return lexiconService.getCollectionList(token);
    }

    @PostMapping("/shareOrCancel")
    public R shareOrCancel(@Param("id") Integer id){
        return lexiconService.shareOrCancel(id);
    }

    @PostMapping("/collectionOrCancel")
    public R collectionOrCancel(HttpServletRequest httpServletRequest,
                                @Param("id") Integer id){
        String token = httpServletRequest.getHeader("authorization");
        return lexiconService.collectionOrCancel(id, token);
    }

    @GetMapping("/lexiconItem")
    public R getLexiconItem(@Param("id") Integer id){
        return lexiconService.getLexiconItem(id);
    }

}
